<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="../../template/tagedu.xhtml">

    <ui:define name="title">
        <title><h:outputText value="TAG - Avaliação Simples"/></title>  
        <f:metadata>
            <f:viewParam name="organization" value="#{performanceMB.organizationID}"/>
        </f:metadata>
        <script type="text/javascript">
            function change_color_in(celula){
                celula.style.backgroundColor="paleturquoise";
            }
            function change_color_out(celula){
                celula.style.backgroundColor="white";
            }
        </script>
    </ui:define>
    <ui:define name="content">
        <f:event type="preRenderComponent" listener="#{performanceMB.init()}"/>
        <h:outputText styleClass="organizationName" value="Notas de #{performanceMB.getOrganizationName()}"/>
        <h:form id="performanceMBForm">
            <p:message for="performanceMBForm" id="messages"/>
            <div class="input-list">
            <h:outputLabel for="unity" class="label" value="Unidade:"/>
            <p:selectOneMenu id="unity" value="#{performanceMB.unityID}">
                <f:selectItems value="#{performanceMB.unityList}"/>
                <p:ajax process="@this" update="performanceMBForm tableGroup"
                        listener="#{performanceMB.listDisciplines()}"/>
            </p:selectOneMenu>
            </div>
            <div class="input-list">
            <h:outputLabel for="discipline" class="label" value="Disciplina:"/>
            <p:selectOneMenu id="discipline" value="#{performanceMB.disciplineID}">
                <f:selectItems value="#{performanceMB.disciplineList}"/>
                <p:ajax process="@this" update="tableGroup"
                        listener="#{performanceMB.configureGrades()}"/>
            </p:selectOneMenu>
            </div>
            <div class="clear"></div>
            <br/>
            <h:panelGroup id="tableGroup">
                <h:panelGroup rendered="#{performanceMB.configureGradesVisible}" id="configureGradeGroup">
                    <p:message id="configureGradeGroupMsg" for="quantity"/>
                    <h:outputLabel for="quantity" value="Número de Avaliações: "/>
                    <p:inputText id="quantity" value="#{performanceMB.grandeQuantity}"/>
                    <p:commandButton value="Salvar" action="#{performanceMB.saveConfiguration()}"
                                     process="@this quantity" update="tableGroup configureGradeGroupMsg"/>
                </h:panelGroup>

                <h:panelGroup id="gradesGroup" 
                              rendered="#{not empty performanceMB.actorList and not performanceMB.configureGradesVisible}">      
                    <p:message id="gradesGroupMsg" for="gradesGroup"/>
                    <table class="performanceTable">

                        <tr>
                            <th style="border-width: 1px; border-color: gray; border-style: outset;
                                padding: 1px; background-color: lightgray">
                                <h:outputText value="Nome"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="AB"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="VA"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="1ª Unidade"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="AB"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="VA"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="2ª Unidade"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="MS"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="RS 1"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="MGS"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="AB"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="VA"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="3ª Unidade"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="AB"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="VA"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="4ª Unidade"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="MS"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="RS 2"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="MGS"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="MA"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="RF"/>
                            </th>
                            <th style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                background-color: lightgray">
                                <h:outputText value="MF"/>
                            </th>
                        </tr>

                        <ui:repeat value="#{performanceMB.actorList}" var="actor">
                            <tr onmouseover="change_color_in(this);" onmouseout="change_color_out(this);">
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:outputText value="#{actor.person.name}"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:inputText value="#{actor.performances.get(0).grade}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:inputText value="#{actor.performances.get(1).grade}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                    background-color: gray">
                                    <h:outputText value="#{performanceMB.firstGrade(performanceMB.actorList.indexOf(actor))}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:inputText value="#{actor.performances.get(2).grade}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:inputText value="#{actor.performances.get(3).grade}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                    background-color: gray">
                                    <h:outputText value="#{performanceMB.secondGrade(performanceMB.actorList.indexOf(actor))}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                    background-color: gray">
                                    <h:outputText value="#{performanceMB.firstSemesterAverage(performanceMB.actorList.indexOf(actor))}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:inputText value="#{actor.performances.get(4).grade}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:outputText value="" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:inputText value="#{actor.performances.get(5).grade}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:inputText value="#{actor.performances.get(6).grade}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                    background-color: gray">
                                    <h:outputText value="#{performanceMB.thirdGrade(performanceMB.actorList.indexOf(actor))}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:inputText value="#{actor.performances.get(7).grade}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:inputText value="#{actor.performances.get(8).grade}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                    background-color: gray">
                                    <h:outputText value="#{performanceMB.fourthGrade(performanceMB.actorList.indexOf(actor))}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px;
                                    background-color: gray">
                                    <h:outputText value="#{performanceMB.secondSemesterAverage(performanceMB.actorList.indexOf(actor))}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:inputText value="#{actor.performances.get(9).grade}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:outputText value="" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:outputText value="" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:inputText value="#{actor.performances.get(10).grade}" style="width: 50px"/>
                                </td>
                                <td style="border-width: 1px; border-color: gray; border-style: outset; padding: 1px">
                                    <h:outputText value="" style="width: 50px"/>
                                </td>
                            </tr>
                        </ui:repeat>
                    </table>
                    <br/>
                    <br/>
                    <p:commandButton ajax="true" action="#{performanceMB.saveGrades()}" 
                                     value="Salvar" process="tableGroup" update="tableGroup gradesGroupMsg"/>
                    <br/>
                    <br/>
                    <h:commandLink rendered="#{not empty performanceMB.actorList and performanceMB.disciplineID != null}" 
                               target="_blank" immediate="true" 
                               value="Baixar em PDF" 
                               action="#{performanceMB.export2()}"/>
                </h:panelGroup>
            </h:panelGroup>
        </h:form>
    </ui:define>

    <ui:define name="modals"></ui:define>
</ui:composition>